#include <bits/stdc++.h>
using namespace std;

class Solution
{
public:
    int main()
    {
        int a, b;
        cin >> a >> b;
        int lowerLen = floor(log10(a)) + 1;
        int upperLen = floor(log10(b)) + 1;
        if (b == 100000000)
        {
            upperLen = 8;
        }
        auto primePalindromes = GetPrimePalindromes(lowerLen, upperLen);
        sort(primePalindromes.begin(), primePalindromes.end());
        for (int num : primePalindromes)
        {
            if (num < a)
            {
                continue;
            }
            else if (num > b)
            {
                break;
            }
            cout << num << endl;
        }
        return 0;
    }

    vector<int> GetPrimePalindromes(int minNumLen, int maxNumLen)
    {
        if (minNumLen > maxNumLen)
        {
            return {};
        }
        vector<int> odds = {1, 3, 5, 7, 9};
        if (maxNumLen == 1)
        {
            return {3, 5, 7};
        }
        vector<int> result;
        for (int firstDigit : odds)
        {
            int base = firstDigit * (1 + pow(10, maxNumLen - 1));
            int innerReverseLen = maxNumLen / 2 - 1;
            int innerUpper = pow(10, innerReverseLen);
            for (int i = 0; i < innerUpper; ++i)
            {
                int reversedI = ReverseIntFixedLength(i, innerReverseLen);
                int palindrome = 0;
                if (maxNumLen & 1)
                {
                    for (int centerDigit = 0; centerDigit <= 9; ++centerDigit)
                    {
                        palindrome = base + i * 10 + reversedI * pow(10, innerReverseLen + 2) + centerDigit * pow(10, innerReverseLen + 1);
                        if (IsPrime(palindrome))
                        {
                            result.push_back(palindrome);
                        }
                    }
                }
                else
                {
                    palindrome = base + i * 10 + reversedI * pow(10, innerReverseLen + 1);
                    if (IsPrime(palindrome))
                    {
                        result.push_back(palindrome);
                    }
                }
            }
        }
        if (minNumLen < maxNumLen)
        {
            vector<int> shorter = GetPrimePalindromes(minNumLen, maxNumLen - 1);
            result.insert(result.end(), shorter.begin(), shorter.end());
        }
        return result;
    }

    static bool IsPrime(int n)
    {
        int upper = sqrt(n);
        for (int i = 2; i <= upper; ++i)
        {
            if (n % i == 0)
            {
                return false;
            }
        }
        return true;
    }

    static int ReverseIntFixedLength(int n, int len)
    {
        if (n == 0)
        {
            return 0;
        }
        int result = 0;
        while (n)
        {
            result *= 10;
            result += n % 10;
            n /= 10;
            --len;
        }
        while (len)
        {
            result *= 10;
            --len;
        }
        return result;
    }
};

#ifndef __LOCAL_TEST__
int main()
{
    return Solution().main();
}
#endif